package com.pet.server.ext.action.square;

import net.sf.json.JSONObject;

import com.pet.server.ext.ActionBase;
import com.pet.server.ext.ApiError;
import com.pet.server.ext.Result;
import com.pet.server.ext.data.PetAdopt;
import com.pet.server.ext.service.UserService;
import com.pet.server.ext.util.NumberUtil;
import com.pet.server.ext.util.Parameters;
import com.pet.server.ext.util.StringUtil;

public class Beadopted extends ActionBase{

	public Integer adopt_id;
	public Beadopted(){
		 needCheckAuth =true;
	}
	@Override
	public void initParameters(Parameters params) throws ApiError {
		adopt_id=NumberUtil.getInteger(params.getFieldValue("adopt_id"));
		if(StringUtil.isEmpty(adopt_id)){
			throw ApiError.Type.INVALID_PARAM.toException();
		}	
	}
	@Override
	public Result invokeService() throws ApiError {
		UserService userService = new UserService();
		PetAdopt adopt = userService.findAdoptById(adopt_id);
		if(null==adopt||!StringUtil.equals(adopt.user_id, user.user_id)){
			throw ApiError.Type.LOGIC_ERROR.toException("数据逻辑错误!");
		}
		userService.updateAdoptState(adopt_id);
		Result result = new Result();
		JSONObject o = new JSONObject();
		o.accumulate("message", "操作成功!");
	    return result;
	}


}
